package com.szdvte.news.dao.impl;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.szdvte.news.bean.News;
import com.szdvte.news.dao.INewsDao;

public class NewsDaoImpl extends BaseDaoImpl implements INewsDao {

	@SuppressWarnings("unchecked")
	@Override
	public List<News> selectNews(News news) {
		List<News> newsList = new ArrayList<News>();
		try {
			newsList = getSqlMapClient().queryForList("news.selectNews",news);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return newsList;
	}

	@Override
	public News loadNews(News news) {
		try {
			news = (News)getSqlMapClient().queryForObject("news.loadNews", news);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return news;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<News> comments(News news) {
		List<News> newsList = new ArrayList<News>();
		try {
			newsList = getSqlMapClient().queryForList("news.comments",news);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return newsList;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<News> pic(News news) {
		List<News> newsList = new ArrayList<News>();
		try {
			newsList = getSqlMapClient().queryForList("news.pic",news);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return newsList;
	}
	private boolean flag;
	@Override
	public boolean add(News news) {
		flag = false;
		try {
			getSqlMapClient().insert("news.add",news);
			getSqlMapClient().insert("news.addNewsBetween",news);
			flag = true;
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return flag;
	}

	@Override
	public boolean update(News news) {
		flag = false;
		try {
			getSqlMapClient().update("news.update",news);
			flag = true;
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return flag;
	}

	@Override
	public boolean delete(News news) {
		flag = false;
		try {
			getSqlMapClient().update("news.delete",news);
			flag = true;
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return flag;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<News> select(News news) {
		List<News> newsList = new ArrayList<News>();
		try {
			newsList = getSqlMapClient().queryForList("news.select",news);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return newsList;
	}
	/**
	 * 获得序列号
	 */
	@Override
	public Integer seq() {
		int seq = 0;
		try {
			seq = (Integer)getSqlMapClient().queryForObject("news.seq");
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return seq;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<News> loadType(News news) {
		List<News> newsList = new ArrayList<News>();
		try {
			newsList = getSqlMapClient().queryForList("news.loadType",news);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return newsList;
	}

}
